package at.chrenko.tu.vs.shared;

import java.io.IOException;

public abstract class ChannelDecorator implements Channel {

	protected Channel decoratedChannel;
	
	public ChannelDecorator(Channel channel) {
		this.decoratedChannel = channel;
	}
	
	public void send(String message) throws IOException {
		if(message == null)
			return;
		
		send(message.getBytes("UTF-8"));
	}
	
	public void send(byte[] message) throws IOException {
		decoratedChannel.send(message);
	}

	public byte[] receive() throws IOException {
		return decoratedChannel.receive();
	}
	
	public String receiveAsString() throws IOException {
		byte[] data = receive();
		
		if(data == null)
			return null;
		
		return new String(data, "UTF-8");
	}
}
